package com.situ.science.controller;

import com.situ.science.pojo.Process;
import com.situ.science.pojo.query.ProcessQuery;
import com.situ.science.service.IProcessService;
import com.situ.science.utils.PageRusults;
import com.situ.science.utils.Result;
import com.situ.science.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/process")
public class ProcessController {
    @Autowired
    private IProcessService processService;

   /* @RequestMapping ("/list")
    public Result list() {//getContests
        List<process> processList = processervice.list();
        return Result.ok(processList);
    }*/

    @RequestMapping("/list")
    public PageRusults list(ProcessQuery processQuery) {
        PageRusults pageRusults = processService.selectByPage(processQuery);
        return pageRusults;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Process process) {
        System.out.println(process);
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer researcherId = (Integer) map.get("id");
        Process process1 = new Process();
        process1.setResearcherId(researcherId);
        process1.setName(process.getName());
        process1.setContent(process.getContent());
        process1.setProjectId(process.getProjectId());
        processService.add(process1);
        return Result.ok();
    }
}
